<script lang="ts" setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router';

//使用手动路由
const router = useRouter();
const redirectRouter = (route: string) => router.push(`/${route}`);

const isCollapse = ref(true)
const switchCollapse = () => {
    isCollapse.value = !isCollapse.value
}
const handleOpen = (key: string, keyPath: string[]) => {
    console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
    console.log(key, keyPath)
}
</script>

<style>
.el-menu-vertical-demo {
    min-height: 100vh;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
}
</style>

<template>
    <el-menu default-active="1" class="el-menu-vertical-demo" :collapse="isCollapse" background-color="#23272e"
        text-color="#fff" active-text-color="#7fffd4" @open="handleOpen" @close="handleClose">
        <el-menu-item index="1" @click="switchCollapse">
            <el-icon>
                <Expand />
            </el-icon>
            <template #title>Expand</template>
        </el-menu-item>
        <el-menu-item index="2" @click="redirectRouter('')">
            <el-icon>
                <House />
            </el-icon>
            <template #title>Home</template>
        </el-menu-item>
        <el-menu-item index="3" @click="redirectRouter('grid')">
            <el-icon>
                <Grid />
            </el-icon>
            <template #title>Grid</template>
        </el-menu-item>
        <el-menu-item index="4">
            <el-icon>
                <setting />
            </el-icon>
            <template #title>Navigator Four</template>
        </el-menu-item>
    </el-menu>
</template>